CFLAGS := -g -O0 -Wall  # 添加调试信息并禁用优化

log:= thirdparty/log.c thirdparty/log.h

json:= thirdparty/cJSON.c thirdparty/cJSON.h

common:= app/app_common.c app/app_common.h

message:= app/app_message.c app/app_message.h

mqtt:=app/app_mqtt.c app/app_mqtt.h

pool:=app/app_pool.c app/app_pool.h	

buffer:=app/app_buffer.c app/app_buffer.h

device:=app/app_device.c app/app_device.h

serial:= app/app_serial.c app/app_serial.h

bt:= app/app_bt.c app/app_bt.h

runner:= app/app_runner.c app/app_runner.h

curl:= ota/ota_http_curl.c ota/ota_http_curl.h

version:=ota/ota_version.c ota/ota_version.h

daemon:= daemon/daemon_sub_process.c daemon/daemon_sub_process.h 
daemon+= daemon/daemon_runner.c daemon/daemon_runner.h
all:= $(bt) $(common)  $(message) $(mqtt) $(pool) $(buffer) $(device) $(serial) $(runner) $(log) $(json)
all+= $(curl) $(version) $(daemon) 

CROSS_COMPILE:= ./toolchain/bin/arm-linux-gnueabihf-gcc 

SYSROOT:= --sysroot=./sysroot

APPNAME:= gateway

all_include:= -Iapp -Ithirdparty
all_include+= -Iota -Idaemon

all_lib:= -lpaho-mqtt3c
all_lib+=  -lcurl  -lcrypto

peer:= root@192.168.42.75

test_log: test/test_log.c  $(log)
	gcc  -o $@  $^ -Ithirdparty
	./$@
	rm -f $@

test_json: test/test_json.c  $(json)
	gcc $(CFLAGS) -o $@  $^ -Ithirdparty
#	./$@
#	rm -f $@

test_common: 
	-gcc $(CFLAGS) -o $@  $(log) test/test_common.c $(common) -Ithirdparty -Iapp
	-./$@
	# rm -f $@

test_message: test/test_message.c  $(message) $(common) $(log) $(json)
	-gcc $(CFLAGS) -o $@  $^ -Iapp -Ithirdparty
	-./$@
	rm -f $@

test_mqtt: test/test_mqtt.c  $(mqtt)   $(log)  
	-gcc $(CFLAGS) -o $@  $^ -Iapp -Ithirdparty -lpaho-mqtt3c
	-./$@
	rm -f $@

test_pool: test/test_pool.c  $(pool)   $(log)  
	-gcc $(CFLAGS) -o $@  $^ -Iapp -Ithirdparty  
	-./$@
	rm -f $@

test_buffer: test/test_buffer.c  $(buffer)   $(log)  
	-gcc $(CFLAGS) -o $@  $^ -Iapp -Ithirdparty  
	-./$@
	rm -f $@


test_device: test/test_device.c $(serial)  $(bt) $(device) $(pool) $(buffer) $(mqtt)  $(message) $(common) $(log) $(json) 
	-gcc $(CFLAGS) -o $@  $^ -Iapp -Ithirdparty   -lpaho-mqtt3c
#	-./$@
#	rm -f $@

test_curl: test/test_curl.c $(curl)   $(log)
	-gcc $(CFLAGS) -o $@  $^ -Iota -Ithirdparty  -lcurl
	-./$@
	rm -f $@


gateway_86: main.c  $(all)
	-gcc $(CFLAGS) -o $@  $^  $(all_include) $(all_lib)  


gateway: main.c  $(all)
	$(CROSS_COMPILE) $(CFLAGS) -o $@  $^  $(all_include) $(all_lib) $(SYSROOT)
	#scp  ./$@   $(peer):/usr/bin/$@

initS99gateway:
	-scp  ./init/S99gateway   $(peer):/etc/init.d/S99gateway
